﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Acms.DataControls;

public partial class Templates_Standard_Default : Acms.AcmsControls.TemplatePage
{

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        pnlSub.ItemDataBound += new Telerik.Web.UI.RadPanelBarEventHandler(pnlSub_ItemDataBound);
        if (!IsPostBack)
        {
            dsSubMenu.SiteId = AcmsContext.SiteId;
            dsSubMenu.CurrentSiteVersion = AcmsContext.SiteVersion;
            if (AcmsContext.CurrentPost != null)
            {
                var paths = AcmsContext.CurrentPost.Path.Split('/').Take(2);
                dsSubMenu.ParentPath = string.Concat(paths.ElementAt(0), "/", paths.Count() > 1 ? paths.ElementAt(1) : "");
            }
        }
    }

    void pnlSub_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)
    {
        var post = e.Item.DataItem as Post;
        if (post != null)
        {
            var paths = post.Path.Split('/').Skip(1);
            System.Text.StringBuilder tmp = new System.Text.StringBuilder();
            tmp.Append("menu");
            foreach (var item in paths)
            {
                tmp.AppendFormat("_{0}", item);
            }
            e.Item.CssClass = tmp.ToString();
        }

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }

    }
}
